package com.stu.spring.context.chapter06.propertyeditor;

import java.beans.PropertyEditorSupport;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

public class CustomDatePropertyEditor extends PropertyEditorSupport {

	private String format = "yyyy-MM-dd";

	private DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern(format);

	@Override
	public void setAsText(String text) throws IllegalArgumentException {
		System.out.println("text = " + text);
		if(null != text && !text.isEmpty()){
			LocalDate localDate = LocalDate.parse(text, FORMATTER);
			this.setValue(localDate);
		}
	}

	public String getFormat() {
		return format;
	}

	public void setFormat(String format) {
		this.format = format;
	}
}
